package org.example.controller;

import org.example.domain.dto.OrderStatus;
import org.example.domain.entity.Order;
import org.example.domain.entity.OrderItem;
import org.example.domain.model.TableData;
import org.example.service.IOrderService;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/*
szy

*/
@RestController
@RequestMapping("/order")
//@CrossOrigin("*")
public class OrderController {
    @Resource
    private IOrderService iOrderService;


    //未支付
    @PostMapping("/nopay")
    public TableData<List<OrderItem>> noPay(OrderStatus orderStatus) {
        System.out.println("===s=d=asf==dsf=");
        System.out.println(orderStatus);
        List<Order> orders = iOrderService.queryById(orderStatus);
        List<String> ordId = new ArrayList<>();
        for (Order order : orders) {
            ordId.add(order.getOrderId());
        }
        List<List<OrderItem>> lists = iOrderService.queryByOrderId(ordId);
        return TableData.buildSuccess(lists.size(), lists);
    }

    //全部订单
    @PostMapping("/allOrder")
    public TableData<List<OrderItem>> allOrder(Integer userId) {
        List<List<OrderItem>> orders = iOrderService.queryByUserId(userId);
        return TableData.buildSuccess(orders.size(), orders);
    }
}

